package mju.cxf.controller.admin;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import mju.cxf.constant.MessageConstant;
import mju.cxf.dto.ProductCategoriesDTO;
import mju.cxf.entity.ProductCategories;
import mju.cxf.result.Result;
import mju.cxf.service.ProductCategoriesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "商品分类接口列表")
@RequestMapping("/admin/api/pcategories")
public class ProductCategoriesController {
    @Autowired
    private ProductCategoriesService productCategoriesService;

    /**
     * 新建商品分类信息
     *
     * @param productCategoriesDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "新建商品分类")
    public Result<String> createProductCategories(@RequestBody ProductCategoriesDTO productCategoriesDTO) {
        System.out.println(productCategoriesDTO);
        return productCategoriesService.saveProductCategories(productCategoriesDTO) ?
                Result.success(MessageConstant.SUCCESS_MESSAGE) :
                Result.error(MessageConstant.FAILURE_MESSAGE);
    }

    /**
     * 新建多个商品分类信息
     *
     * @param productCategoriesDTO
     * @return
     */
    @PostMapping("/adds")
    @ApiOperation(value = "新建商品分类")
    public Result<String> createProductCategoriess(@RequestBody List<ProductCategoriesDTO> productCategoriesDTO) {
        return productCategoriesService.saveProductCategoriess(productCategoriesDTO) ?
                Result.success(MessageConstant.SUCCESS_MESSAGE) :
                Result.error(MessageConstant.FAILURE_MESSAGE);
    }

    /**
     * 批量删除商品分类信息
     *
     * @param productCategoriesDTO
     * @return
     */
    @DeleteMapping("/delete/batch")
    @ApiOperation(value = "批量删除商品分类信息", notes = "管理员通过此接口批量删除商品分类信息")
    public Result<String> deleteCategories(@RequestBody List<ProductCategoriesDTO> productCategoriesDTO) {
        return productCategoriesService.deleteProductCategoriess(productCategoriesDTO) ?
                Result.success(MessageConstant.SUCCESS_MESSAGE) :
                Result.error(MessageConstant.FAILURE_MESSAGE);
    }

    /**
     * 查询所有商品分类
     *
     * @return
     */
    @GetMapping("/all")
    @ApiOperation(value = "查询所有商品分类")
    public Result<List<ProductCategories>> getProductCategoriesAll() {
        return Result.success(productCategoriesService.getAllProductCategories());
    }
}
